﻿// tinyxml2_test.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
#include "XmlUtil.h"

using namespace std;
using namespace tinyxml2;

void example2()
{
	XMLDocument doc;
	doc.LoadFile("test.xml");

	XMLElement* root = doc.RootElement();
	printf("Root - Name: %s \r\n\r\n", root->Name());	// 跟元素名

	XMLElement* node = root->FirstChildElement("CmdType");
	if (node)
	{
		printf("Node - Name: %s \r\n", node->Name());
		printf("Node - Text: %s \r\n", node->GetText());	// 元素内容
	}
	const char* DeviceID = root->FirstChildElement("DeviceID")->GetText();
	printf("DeviceID,%s\n", DeviceID);

	XMLElement* surface = root->FirstChildElement("DeviceList");
	if (surface)
	{
		printf("surface - Name: %s \r\n", surface->Name());
		/* 从元素List */
		XMLElement* Item = surface->FirstChildElement("Item");
		while (Item)
		{
			printf("Item - Name: %s\r\n", Item->Name());
			const char* DeviceID = Item->FirstChildElement("DeviceID")->GetText();
			printf("DeviceID,%s\n", DeviceID);
			Item = Item->NextSiblingElement("Item");
		}
	}
}

int main()
{
	//CXmlUtil* m_XmlUtil = new CXmlUtil();
	//m_XmlUtil->ParseFile("test.xml");
	//const char* CmdType = m_XmlUtil->GetFieldString("CmdType");
	//int count = m_XmlUtil->GetNumChannel();

	example2();
}
